//
//  UITextView+RAC.m
//  高仿暴走斗图
//
//  Created by huangsongyao on 16/3/26.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "UITextView+RAC.h"

#ifdef __IPHONE_8_0
// suppress these errors until we are ready to handle them
#pragma clang diagnostic ignored "-Wobjc-designated-initializers"

#else
// temporarily define an empty NS_DESIGNATED_INITIALIZER so we can use now,
// will be ready for iOS8 SDK
#define NS_DESIGNATED_INITIALIZER

#endif

@implementation UITextView (RAC)

+ (UITextView *)rac_createTextViewForBorderWidth:(CGFloat)borderWidth borderColor:(UIColor *)borderColor textAlignment:(NSTextAlignment)textAlignment font:(UIFont *)font returnKeyType:(UIReturnKeyType)returnKeyType textColor:(UIColor *)textColor bkColor:(UIColor *)bkColor keyboardType:(UIKeyboardType)keyboardType signalCompletion:(void(^)(id x))completion {
    
    return [[self alloc] initWithRAC_createTextViewForBorderWidth:borderWidth
                                                      borderColor:borderColor
                                                    textAlignment:textAlignment
                                                             font:font
                                                    returnKeyType:returnKeyType
                                                        textColor:textColor
                                                          bkColor:bkColor
                                                     keyboardType:keyboardType
                                                 signalCompletion:completion];
}

- (UITextView *)initWithRAC_createTextViewForBorderWidth:(CGFloat)borderWidth borderColor:(UIColor *)borderColor textAlignment:(NSTextAlignment)textAlignment font:(UIFont *)font returnKeyType:(UIReturnKeyType)returnKeyType textColor:(UIColor *)textColor bkColor:(UIColor *)bkColor keyboardType:(UIKeyboardType)keyboardType signalCompletion:(void(^)(id x))completion {
    
    if (self = [super initWithFrame:CGRectZero]) {
        
        self.layer.borderWidth = borderWidth;
        self.layer.borderColor = CLEAR_COLOR.CGColor;
        self.textAlignment = textAlignment;
        self.font = font;
        self.returnKeyType = returnKeyType;
        self.keyboardType = keyboardType;
        self.textColor = textColor;
        self.backgroundColor = bkColor;
        
        [[[self rac_textSignal] deliverOn:[RACScheduler mainThreadScheduler]] subscribeNext:^(id x) {
            if (completion) {
                completion(x);
            }
        }];
    }
    return self;
}

@end
